/**
*  @author: yaoyuan
*  Description: Routes Index
*  created: 2015.04.08
**/
import path from 'path';
import fs from 'fs';

export default class Routes{

	constructor(dao) {

		this.classPath = _u.classPath;
		// 指向根目录的相对位置
		this.relativePath = path.relative(__dirname, this.classPath);
	}
	init(router) {
		this.router = router;
		this.mapController();
	}
	mapController() {
	
		let ServerConfig, relativePath, _this;
		function _Map(options) {

			var _conts = options.mapping;
			_conts = _u.type(_conts) === 'string' ? [_conts] : _conts;
			
			for (let i = _conts.length - 1; i >= 0; i--) {
				

			/**	_ds.forEach(function(obj) {
					let stat = fs.statSync(path.join(_p,obj));
					if(stat.is)
				});
			**/
			//   try{
			   	let _p = path.join(_u.classPath, _conts[i]),
					_ds = fs.readdirSync(_p);				
			/**	_ds.forEach(function(obj) {
			   		_u.log(path.join(relativePath, _conts[i], obj));
					require(path.join(relativePath, _conts[i], obj));
				});		
			   }catch(e){
			   		_u.error('jia zai controller error (', e, ')');
			   } **/
			   _u.router({classPath: _u.classPath, p: _p, ds: _ds});
			}
			

		}

		
		relativePath = this.relativePath;
		ServerConfig = _u.config.servlet;
		_this = this;
		for (let i in ServerConfig) _Map(ServerConfig[i]);
		_u.router.create(function() {
			_this.router( require( path.join(this.relativePath, _u.router.path)));
		});
		return this;
		
	}
}
/**
			  (路由配置初始化)
用户请求--->>  路由匹配 --->> 数据过滤(vo->entriy) --->>


**/